/*
 * @(#)AutoCompleteInputBoxTag.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.dms.core;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;

import com.dcivision.framework.AutoCompleteInputBoxManager;
import com.dcivision.framework.DataSourceFactory;
import com.dcivision.framework.SessionContainer;

/**
 UserNameManager.java
 
 @author      Jim Zhou
 @company     DCIVision Limited
 @creation date   2006/09/19
 @version     $Revision: 1.3.2.1 $
 */

public class UserNameManager implements AutoCompleteInputBoxManager {
  
  protected Log log = new LogFactoryImpl().getInstance(this.getClass());
  
  public UserNameManager() {
    super();
    
  }
  
  public String getOnReceiveJSFunction() {
    
    return null;
  }
  
  public String getOnSelectJSFunction() {
    
    return null;
  }
  
  public String getOnTimeoutJSFunction() {
    
    return null;
  }
  
  public List retrieveInformation(String[] args,
      SessionContainer sessionContainer) {    
    Connection conn = null;
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    ArrayList result = new ArrayList();
    
    try{
      conn = DataSourceFactory.getConnection();
      synchronized (conn) {
        sqlStat.append("SELECT FULL_NAME FROM USER_RECORD ");
        preStat = conn.prepareStatement(sqlStat.toString());
        rs = preStat.executeQuery();
        while(rs.next()){
          result.add(rs.getString("FULL_NAME"));
        }
        return result;
      }
    } catch (SQLException sqle) {
      log.error(sqle, sqle);
      //throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle,sqle.toString());
    } catch (Exception e) {
      log.error(e, e);
      //throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
    } finally {
      try {
        rs.close();
      } catch (Exception ignore) {} finally {
        rs = null;
      }
      try {
        conn.close();
      } catch (Exception ignore) {} finally {
        conn = null;
      }
      try {
        preStat.close();
      } catch (Exception ignore) {} finally {
        preStat = null;
      }
    }
    
    return null;
  }
  
}
